package day1.homework.four;

import java.util.TreeSet;

/**
 * @创建人 MBY381
 * @创建时间 2022/6/27 23:34
 * @描述 暂无
 */
public class TestFour {
    public static void main(String[] args) {
        TreeSet<Student1> treeSet1 = new TreeSet<>();
        Student1 s1 = new Student1("liusan", 20, 90.0F);
        Student1 s2 = new Student1("lisi", 22, 90.0F);
        Student1 s3 = new Student1("wangwu", 20, 99.0F);
        Student1 s4 = new Student1("sunliu", 20, 100.0F);

        //乱序插入
        treeSet1.add(s1);
        treeSet1.add(s2);
        treeSet1.add(s4);
        treeSet1.add(s3);

        //顺序输出
        System.out.println(treeSet1);


        //lambda 简化式Comparator写法
        TreeSet<Student2> treeSet2 = new TreeSet<>((o1, o2) -> {
            if (o1.score == o2.score) {
                return o1.age - o2.age;
            }
            return (int) (o1.score - o2.score);
        });

        Student2 s5 = new Student2("liusan", 20, 90.0F);
        Student2 s6 = new Student2("sunliu", 20, 100.0F);
        Student2 s7 = new Student2("lisi", 22, 90.0F);
        Student2 s8 = new Student2("wangwu", 20, 99.0F);

        //乱序插入
        treeSet2.add(s5);
        treeSet2.add(s6);
        treeSet2.add(s7);
        treeSet2.add(s8);

        //顺序输出
        System.out.println(treeSet2);

    }
}
